from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy import and_, or_, Column, BigInteger, Date,String,UniqueConstraint
from sqlalchemy import SmallInteger, DateTime, Integer, LargeBinary
from datetime import datetime


Base = declarative_base()

#Base
#是ORM模型的基类
# ORM模型 - Obj里面的属性 == table中创建的字段

from sqlalchemy import Column, Integer, INT, INTEGER, VARCHAR, String


# 以上的基本数据类型和对象封装类型都是可以使用的，看个人喜好

class Futu_Token(Base):
    __tablename__ = 'futu_token'
    id = Column(Integer, primary_key=True, autoincrement=True)
    token = Column(String(32))

class futu_rank_list(Base):
    __tablename__ = 'tb_futu_rank_list'
    id  =Column('id',BigInteger, primary_key=True, autoincrement=True)
    date =Column(Date)
    code = Column('code',String(16))
    name = Column('name',String(128))
    futu_id = Column('futu_id',BigInteger)
    marketVal = Column('marketVal',String(24))
    circulationMarketValue = Column('circulationMarketValue',String(24))
    totalShares= Column('totalShares',String(24))
    circulationShares = Column('circulationShares', String(24))
    priceNominal = Column('priceNominal',String(24))
    create_ts = Column('create_ts',DateTime, default=datetime.now)
    update_ts = Column('update_ts', DateTime, default=datetime.now)
    day5= Column('day5',String(16))
    day10= Column('day10',String(16))
    day20= Column('day20',String(16))
    day30= Column('day30',String(16))
    day60= Column('day60',String(16))
    day120= Column('day120',String(16))
    day250= Column('day250',String(16))
    year= Column('year',String(16))
    trustAum =  Column('trustAum',String(24))
    leverage = Column('leverage',String(24))
    tradeChangeRatio= Column('tradeChangeRatio',String(24))
    volumnRatio = Column('volumnRatio',String(24))
    buysellRatio = Column('buysellRatio',String(24))
    changeRatio = Column('changeRatio',String(24))
    tradeTrunover = Column('tradeTrunover',String(24))
    tradeVolumn  = Column('tradeVolumn',String(24))
    priceAmplitude = Column('priceAmplitude',String(24))

    __table_args__ = (
        UniqueConstraint('date', 'code',name='futu_rank_list_pk'),  # 姓名和年龄唯一
    )
# 在基类中寻找所有继承自我的Class，在engine里实现
engine = create_engine('mysql+pymysql://root:Zk!123456@192.168.0.109:3306/db_longbridge')
#创建数据表
#Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
